home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / ext / gstreamer / compressor.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  5KB  |  120 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import Gst, Gtk, GObject
  5. from quodlibet.plugins import PluginImportException
  6. from quodlibet.plugins.gstelement import GStreamerPlugin
  7. from quodlibet import qltk
  8. from quodlibet import config
  9. _PLUGIN_ID = 'compressor'
  10. _SETTINGS = {
  11.     'threshold': [
  12.         _('_Threshold:'),
  13.         _('Threshold until the filter is activated'),
  14.         1],
  15.     'ratio': [
  16.         _('R_atio:'),
  17.         _('Compression ratio'),
  18.         1] }
  19.  
  20. def get_cfg(option):
  21.     cfg_option = '%s_%s' % (_PLUGIN_ID, option)
  22.     default = _SETTINGS[option][2]
  23.     if option == 'threshold':
  24.         return config.getfloat('plugins', cfg_option, default)
  25.     if None == 'ratio':
  26.         return config.getfloat('plugins', cfg_option, default)
  27.  
  28.  
  29. def set_cfg(option, value):
  30.     cfg_option = '%s_%s' % (_PLUGIN_ID, option)
  31.     if get_cfg(option) != value:
  32.         config.set('plugins', cfg_option, value)
  33.  
  34.  
  35. class Preferences(Gtk.VBox):
  36.     __gsignals__ = {
  37.         'changed': (GObject.SignalFlags.RUN_LAST, None, tuple()) }
  38.     
  39.     def __init__(self):
  40.         super(Preferences, self).__init__(spacing = 12)
  41.         table = Gtk.Table(n_rows = 2, n_columns = 2)
  42.         table.set_col_spacings(6)
  43.         table.set_row_spacings(6)
  44.         labels = { }
  45.         for idx, key in enumerate([
  46.             'threshold',
  47.             'ratio']):
  48.             (text, tooltip) = _SETTINGS[key][:2]
  49.             label = Gtk.Label(label = text)
  50.             labels[key] = label
  51.             label.set_tooltip_text(tooltip)
  52.             label.set_alignment(0, 0.5)
  53.             label.set_padding(0, 6)
  54.             label.set_use_underline(True)
  55.             table.attach(label, 0, 1, idx, idx + 1, xoptions = Gtk.AttachOptions.FILL | Gtk.AttachOptions.SHRINK)
  56.         
  57.         threshold_scale = Gtk.HScale(adjustment = Gtk.Adjustment.new(0, 0, 1, 0.01, 0.1, 0))
  58.         threshold_scale.set_digits(2)
  59.         labels['threshold'].set_mnemonic_widget(threshold_scale)
  60.         threshold_scale.set_value_pos(Gtk.PositionType.RIGHT)
  61.         
  62.         def format_perc(scale, value):
  63.             return _('%d %%') % value * 100
  64.  
  65.         threshold_scale.connect('format-value', format_perc)
  66.         table.attach(threshold_scale, 1, 2, 0, 1)
  67.         
  68.         def threshold_changed(scale):
  69.             value = scale.get_value()
  70.             set_cfg('threshold', value)
  71.             self.emit('changed')
  72.  
  73.         threshold_scale.connect('value-changed', threshold_changed)
  74.         threshold_scale.set_value(get_cfg('threshold'))
  75.         ratio_scale = Gtk.HScale(adjustment = Gtk.Adjustment.new(0, 0, 1, 0.01, 0.1, 0))
  76.         ratio_scale.set_digits(2)
  77.         labels['ratio'].set_mnemonic_widget(ratio_scale)
  78.         ratio_scale.set_value_pos(Gtk.PositionType.RIGHT)
  79.         table.attach(ratio_scale, 1, 2, 1, 2)
  80.         
  81.         def ratio_changed(scale):
  82.             value = scale.get_value()
  83.             set_cfg('ratio', value)
  84.             self.emit('changed')
  85.  
  86.         ratio_scale.connect('value-changed', ratio_changed)
  87.         ratio_scale.set_value(get_cfg('ratio'))
  88.         self.pack_start(qltk.Frame(_('Preferences'), child = table), True, True, 0)
  89.  
  90.  
  91.  
  92. class Compressor(GStreamerPlugin):
  93.     PLUGIN_ID = _PLUGIN_ID
  94.     PLUGIN_NAME = _('Audio Compressor')
  95.     PLUGIN_DESC = _('Change the amplitude of all samples above a specific threshold with a specific ratio.')
  96.     PLUGIN_ICON = 'audio-volume-high'
  97.     
  98.     def setup_element(cls):
  99.         return Gst.ElementFactory.make('audiodynamic', cls.PLUGIN_ID)
  100.  
  101.     setup_element = classmethod(setup_element)
  102.     
  103.     def update_element(cls, element):
  104.         element.set_property('characteristics', 'soft-knee')
  105.         element.set_property('mode', 'compressor')
  106.         element.set_property('ratio', get_cfg('ratio'))
  107.         element.set_property('threshold', get_cfg('threshold'))
  108.  
  109.     update_element = classmethod(update_element)
  110.     
  111.     def PluginPreferences(cls, window):
  112.         prefs = Preferences()
  113.         prefs.connect(('changed',), (lambda : cls.queue_update()))
  114.         return prefs
  115.  
  116.     PluginPreferences = classmethod(PluginPreferences)
  117.  
  118. if not Compressor.setup_element():
  119.     raise PluginImportException("GStreamer element 'audiodynamic' missing (gst-plugins-good)")
  120.